/*   1:    */ package com.rinsi.core.service;
/*   2:    */ 
/*   3:    */ import com.rinsi.util.AssertUtil;
/*   4:    */ import com.rinsi.util.MapUtil;
/*   5:    */ import java.util.List;
/*   6:    */ import java.util.Map;
/*   7:    */ import org.apache.log4j.Logger;
/*   8:    */ import org.mybatis.spring.SqlSessionTemplate;
/*   9:    */ 
/*  10:    */ public abstract class CoreSimpleService
/*  11:    */   extends CoreService
/*  12:    */ {
/*  13: 23 */   private static Logger logger = Logger.getLogger(CoreSimpleService.class);
/*  14:    */   
/*  15:    */   public Map<String, Object> list(Map<String, Object> model)
/*  16:    */   {
/*  17: 33 */     Map<String, Object> params = getParams(model);
/*  18:    */     
/*  19: 35 */     Map<String, Object> config = getConfig(model);
/*  20:    */     
/*  21: 37 */     Map<String, Object> rMap = getRMap();
/*  22:    */     try
/*  23:    */     {
/*  24: 41 */       beforeList(model);
/*  25:    */       
/*  26: 43 */       Integer page = MapUtil.getInteger(params, "page");
/*  27:    */       
/*  28: 45 */       Integer rows = MapUtil.getInteger(params, "rows");
/*  29:    */       
/*  30: 47 */       List<Map<String, Object>> datas = getSqlSessionTemplate().selectList(namespace(config) + ".list", params);
/*  31: 49 */       if ((MapUtil.getInteger(config, "module.page") != null) && (MapUtil.getInteger(config, "module.page").intValue() == 1)) {
/*  32: 51 */         if (AssertUtil.isCollectionNotEmpty(datas))
/*  33:    */         {
/*  34: 53 */           rMap.put("total", Integer.valueOf(datas.size()));
/*  35:    */           
/*  36: 55 */           Integer begin = Integer.valueOf((page.intValue() - 1) * rows.intValue());
/*  37:    */           
/*  38: 57 */           Integer end = Integer.valueOf(page.intValue() * rows.intValue());
/*  39: 59 */           if (end.intValue() > datas.size()) {
/*  40: 61 */             end = Integer.valueOf(datas.size());
/*  41:    */           }
/*  42: 64 */           datas = datas.subList(begin.intValue(), end.intValue());
/*  43:    */         }
/*  44:    */         else
/*  45:    */         {
/*  46: 68 */           rMap.put("total", Integer.valueOf(0));
/*  47:    */         }
/*  48:    */       }
/*  49: 72 */       rMap.put("datas", datas);
/*  50:    */     }
/*  51:    */     catch (Exception ex)
/*  52:    */     {
/*  53: 76 */       rMap.put("success", Boolean.valueOf(false));
/*  54: 78 */       if (MapUtil.getBoolean(rMap, "shoeExMessage").booleanValue()) {
/*  55: 80 */         rMap.put("message", ex.getMessage());
/*  56:    */       } else {
/*  57: 84 */         rMap.put("message", "展示数据列表出错！请稍后重试，或联系系统管理员！");
/*  58:    */       }
/*  59: 87 */       rMap.put("ex", ex.getMessage());
/*  60:    */       
/*  61: 89 */       ex.printStackTrace();
/*  62:    */     }
/*  63: 92 */     afterList(model, rMap);
/*  64: 94 */     if (logger.isDebugEnabled()) {
/*  65: 96 */       logger.debug("list提交信息：" + MapUtil.json(model) + "和返回信息" + MapUtil.json(rMap));
/*  66:    */     }
/*  67:100 */     return rMap;
/*  68:    */   }
/*  69:    */   
/*  70:    */   public void beforeList(Map<String, Object> model) {}
/*  71:    */   
/*  72:    */   public void afterList(Map<String, Object> model, Map<String, Object> rMap) {}
/*  73:    */   
/*  74:    */   public Map<String, Object> item(Map<String, Object> model)
/*  75:    */   {
/*  76:117 */     Map<String, Object> params = getParams(model);
/*  77:    */     
/*  78:119 */     Map<String, Object> config = getConfig(model);
/*  79:    */     
/*  80:121 */     Map<String, Object> rMap = getRMap();
/*  81:    */     try
/*  82:    */     {
/*  83:125 */       beforeItem(model);
/*  84:    */       
/*  85:127 */       rMap.put("data", getSqlSessionTemplate().selectOne(namespace(config) + ".get", params));
/*  86:    */     }
/*  87:    */     catch (Exception ex)
/*  88:    */     {
/*  89:131 */       rMap.put("success", Boolean.valueOf(false));
/*  90:133 */       if (MapUtil.getBoolean(rMap, "shoeExMessage").booleanValue()) {
/*  91:135 */         rMap.put("message", ex.getMessage());
/*  92:    */       } else {
/*  93:139 */         rMap.put("message", "获取数据出错！请稍后重试，或联系系统管理员！");
/*  94:    */       }
/*  95:142 */       rMap.put("ex", ex.getMessage());
/*  96:    */       
/*  97:144 */       ex.printStackTrace();
/*  98:    */     }
/*  99:148 */     afterItem(model, rMap);
/* 100:150 */     if (logger.isDebugEnabled()) {
/* 101:152 */       logger.debug("item提交信息：" + MapUtil.json(model) + "和返回信息" + MapUtil.json(rMap));
/* 102:    */     }
/* 103:156 */     return rMap;
/* 104:    */   }
/* 105:    */   
/* 106:    */   public void beforeItem(Map<String, Object> model) {}
/* 107:    */   
/* 108:    */   public void afterItem(Map<String, Object> model, Map<String, Object> rMap) {}
/* 109:    */   
/* 110:    */   public Map<String, Object> save(Map<String, Object> model)
/* 111:    */   {
/* 112:172 */     Map<String, Object> params = getParams(model);
/* 113:    */     
/* 114:174 */     Map<String, Object> config = getConfig(model);
/* 115:    */     
/* 116:176 */     Map<String, Object> rMap = getRMap();
/* 117:    */     try
/* 118:    */     {
/* 119:180 */       if (!AssertUtil.isStringNotEmpty(params.get(config.get("module.idCol"))))
/* 120:    */       {
/* 121:182 */         String key = getKey(config);
/* 122:    */         
/* 123:184 */         params.put(MapUtil.getString(config, "module.idCol"), key);
/* 124:    */         
/* 125:186 */         beforeInsert(model);
/* 126:    */         
/* 127:188 */         getSqlSessionTemplate().insert(namespace(config) + ".insert", params);
/* 128:    */       }
/* 129:    */       else
/* 130:    */       {
/* 131:192 */         beforeUpdate(model);
/* 132:    */         
/* 133:194 */         getSqlSessionTemplate().update(namespace(config) + ".update", params);
/* 134:    */       }
/* 135:197 */       rMap.put("data", getSqlSessionTemplate().selectOne(namespace(config) + ".get", params));
/* 136:    */     }
/* 137:    */     catch (Exception ex)
/* 138:    */     {
/* 139:201 */       rMap.put("success", Boolean.valueOf(false));
/* 140:203 */       if (MapUtil.getBoolean(rMap, "shoeExMessage").booleanValue()) {
/* 141:205 */         rMap.put("message", ex.getMessage());
/* 142:    */       } else {
/* 143:209 */         rMap.put("message", "保存数据出错！请稍后重试，或联系系统管理员！");
/* 144:    */       }
/* 145:212 */       rMap.put("ex", ex.getMessage());
/* 146:    */       
/* 147:214 */       ex.printStackTrace();
/* 148:    */     }
/* 149:217 */     if (!AssertUtil.isStringNotEmpty(params.get(config.get("module.idCol")))) {
/* 150:219 */       afterInsert(model, rMap);
/* 151:    */     } else {
/* 152:223 */       afeterUpdate(model, rMap);
/* 153:    */     }
/* 154:226 */     if (logger.isDebugEnabled()) {
/* 155:228 */       logger.debug("save提交信息：" + MapUtil.json(model) + "和返回信息" + MapUtil.json(rMap));
/* 156:    */     }
/* 157:232 */     return rMap;
/* 158:    */   }
/* 159:    */   
/* 160:    */   public void beforeInsert(Map<String, Object> model) {}
/* 161:    */   
/* 162:    */   public void afterInsert(Map<String, Object> model, Map<String, Object> rMap) {}
/* 163:    */   
/* 164:    */   public void beforeUpdate(Map<String, Object> model) {}
/* 165:    */   
/* 166:    */   public void afeterUpdate(Map<String, Object> model, Map<String, Object> rMap) {}
/* 167:    */   
/* 168:    */   public Map<String, Object> del(Map<String, Object> model)
/* 169:    */   {
/* 170:253 */     Map<String, Object> params = getParams(model);
/* 171:    */     
/* 172:255 */     Map<String, Object> config = getConfig(model);
/* 173:    */     
/* 174:257 */     Map<String, Object> rMap = getRMap();
/* 175:    */     try
/* 176:    */     {
/* 177:261 */       String[] IDs = MapUtil.getString(params, "IDs").split(",");
/* 178:263 */       for (int i = 0; i < IDs.length; i++)
/* 179:    */       {
/* 180:265 */         params.put(MapUtil.getString(config, "module.idCol"), IDs[i].trim());
/* 181:    */         
/* 182:267 */         params.putAll((Map)getSqlSessionTemplate().selectOne(namespace(config) + ".get", params));
/* 183:    */         
/* 184:269 */         beforeDel(model);
/* 185:    */         
/* 186:271 */         getSqlSessionTemplate().delete(namespace(config) + ".del", params);
/* 187:    */       }
/* 188:    */     }
/* 189:    */     catch (Exception ex)
/* 190:    */     {
/* 191:276 */       rMap.put("success", Boolean.valueOf(false));
/* 192:278 */       if (MapUtil.getBoolean(rMap, "shoeExMessage").booleanValue()) {
/* 193:280 */         rMap.put("message", ex.getMessage());
/* 194:    */       } else {
/* 195:284 */         rMap.put("message", "数据删除出错！请稍后重试，或联系系统管理员！");
/* 196:    */       }
/* 197:287 */       rMap.put("ex", ex.getMessage());
/* 198:    */       
/* 199:289 */       ex.printStackTrace();
/* 200:    */     }
/* 201:292 */     afterDel(model, rMap);
/* 202:294 */     if (logger.isDebugEnabled()) {
/* 203:296 */       logger.debug("del提交信息：" + MapUtil.json(model) + "和返回信息" + MapUtil.json(rMap));
/* 204:    */     }
/* 205:300 */     return rMap;
/* 206:    */   }
/* 207:    */   
/* 208:    */   public void beforeDel(Map<String, Object> model) {}
/* 209:    */   
/* 210:    */   public void afterDel(Map<String, Object> model, Map<String, Object> rMap) {}
/* 211:    */   
/* 212:    */   public Map<String, Object> lock(Map<String, Object> model)
/* 213:    */   {
/* 214:317 */     Map<String, Object> params = getParams(model);
/* 215:    */     
/* 216:319 */     Map<String, Object> config = getConfig(model);
/* 217:    */     
/* 218:321 */     Map<String, Object> rMap = getRMap();
/* 219:    */     try
/* 220:    */     {
/* 221:324 */       String[] IDs = MapUtil.getString(params, "IDs").split(",");
/* 222:326 */       for (int i = 0; i < IDs.length; i++)
/* 223:    */       {
/* 224:328 */         params.put(MapUtil.getString(config, "module.idCol"), IDs[i].trim());
/* 225:    */         
/* 226:330 */         params.putAll((Map)getSqlSessionTemplate().selectOne(namespace(config) + ".get", params));
/* 227:    */         
/* 228:332 */         beforeLock(model);
/* 229:    */         
/* 230:334 */         getSqlSessionTemplate().delete(namespace(config) + ".lock", params);
/* 231:    */       }
/* 232:337 */       rMap.put("data", getSqlSessionTemplate().selectOne(namespace(config) + ".get", params));
/* 233:    */     }
/* 234:    */     catch (Exception ex)
/* 235:    */     {
/* 236:341 */       rMap.put("success", Boolean.valueOf(false));
/* 237:343 */       if (MapUtil.getBoolean(rMap, "shoeExMessage").booleanValue()) {
/* 238:345 */         rMap.put("message", ex.getMessage());
/* 239:    */       } else {
/* 240:349 */         rMap.put("message", "数据加锁出错！请稍后重试，或联系系统管理员！");
/* 241:    */       }
/* 242:352 */       rMap.put("ex", ex.getMessage());
/* 243:    */       
/* 244:354 */       ex.printStackTrace();
/* 245:    */     }
/* 246:357 */     afterLock(model, rMap);
/* 247:359 */     if (logger.isDebugEnabled()) {
/* 248:361 */       logger.debug("lock提交信息：" + MapUtil.json(model) + "和返回信息" + MapUtil.json(rMap));
/* 249:    */     }
/* 250:365 */     return rMap;
/* 251:    */   }
/* 252:    */   
/* 253:    */   public void beforeLock(Map<String, Object> model) {}
/* 254:    */   
/* 255:    */   public void afterLock(Map<String, Object> model, Map<String, Object> rMap) {}
/* 256:    */   
/* 257:    */   public Map<String, Object> unlock(Map<String, Object> model)
/* 258:    */   {
/* 259:382 */     Map<String, Object> params = getParams(model);
/* 260:    */     
/* 261:384 */     Map<String, Object> config = getConfig(model);
/* 262:    */     
/* 263:386 */     Map<String, Object> rMap = getRMap();
/* 264:    */     try
/* 265:    */     {
/* 266:389 */       String[] IDs = MapUtil.getString(params, "IDs").split(",");
/* 267:391 */       for (int i = 0; i < IDs.length; i++)
/* 268:    */       {
/* 269:393 */         params.put(MapUtil.getString(config, "module.idCol"), IDs[i].trim());
/* 270:    */         
/* 271:395 */         params.putAll((Map)getSqlSessionTemplate().selectOne(namespace(config) + ".get", params));
/* 272:    */         
/* 273:397 */         beforeUnlock(model);
/* 274:399 */         if (MapUtil.getBoolean(config, "module.checkUnlock").booleanValue())
/* 275:    */         {
/* 276:401 */           Integer count = (Integer)getSqlSessionTemplate().selectOne(namespace(config) + ".checkUnlock", params);
/* 277:403 */           if (count.intValue() > 0)
/* 278:    */           {
/* 279:405 */             rMap.put("shoeExMessage", Boolean.valueOf(true));
/* 280:    */             
/* 281:407 */             throw new Exception("数据已经被引用，不能解锁！");
/* 282:    */           }
/* 283:    */         }
/* 284:411 */         getSqlSessionTemplate().delete(namespace(config) + ".unlock", params);
/* 285:    */       }
/* 286:414 */       rMap.put("data", getSqlSessionTemplate().selectOne(namespace(config) + ".get", params));
/* 287:    */     }
/* 288:    */     catch (Exception ex)
/* 289:    */     {
/* 290:418 */       rMap.put("success", Boolean.valueOf(false));
/* 291:420 */       if (MapUtil.getBoolean(rMap, "shoeExMessage").booleanValue()) {
/* 292:422 */         rMap.put("message", ex.getMessage());
/* 293:    */       } else {
/* 294:426 */         rMap.put("message", "数据解锁出错！请稍后重试，或联系系统管理员！");
/* 295:    */       }
/* 296:429 */       rMap.put("ex", ex.getMessage());
/* 297:    */       
/* 298:431 */       ex.printStackTrace();
/* 299:    */     }
/* 300:434 */     afterUnlock(model, rMap);
/* 301:436 */     if (logger.isDebugEnabled()) {
/* 302:438 */       logger.debug("unlock提交信息：" + MapUtil.json(model) + "和返回信息" + MapUtil.json(rMap));
/* 303:    */     }
/* 304:442 */     return rMap;
/* 305:    */   }
/* 306:    */   
/* 307:    */   public void beforeUnlock(Map<String, Object> model) {}
/* 308:    */   
/* 309:    */   public void afterUnlock(Map<String, Object> model, Map<String, Object> rMap) {}
/* 310:    */   
/* 311:    */   public Map<String, Object> getOrganImg(Map<String, Object> model)
/* 312:    */   {
/* 313:456 */     Map<String, Object> params = getParams(model);
/* 314:    */     
/* 315:458 */     Map<String, Object> datas = (Map)getSqlSessionTemplate().selectOne("core.getOrgan", MapUtil.getString(params, "ORGAN_ID"));
/* 316:    */     try
/* 317:    */     {
/* 318:462 */       return datas;
/* 319:    */     }
/* 320:    */     catch (Exception ex)
/* 321:    */     {
/* 322:466 */       ex.printStackTrace();
/* 323:471 */       if (logger.isDebugEnabled()) {
/* 324:473 */         logger.debug("organImg提交信息：" + MapUtil.json(model) + "和返回信息" + MapUtil.json(datas));
/* 325:    */       }
/* 326:    */     }
/* 327:477 */     return params;
/* 328:    */   }
/* 329:    */ }


/* Location:           D:\Users\Desktop\shanxi\项目\sxazmis\WEB-INF\classes\
 * Qualified Name:     com.rinsi.core.service.CoreSimpleService
 * JD-Core Version:    0.7.0.1
 */